function Slider(from,direction,container_id,timeout,module,extra_params)
{
	var container = "#"+container_id;
	$(container).prepend('<div class="loader" style="margin-top:-20px;margin-left:'+parseInt($(container).width()-20)+'px;"></div>');
	from = from;
	action = 'Slider';
	module = module;
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
			$(".loader").remove();
            //get errors from backend
            if(req.responseText)
            {
                $.facebox(req.responseText);
            }
			//get data from backend		
            if (req.responseJS.output)
            {
            	nav = req.responseJS.navigation;
            	switch(direction)
            	{
            		case 'prev':
            			$(container+' .Slider-content-scroller').width(parseInt(width*2)+'px');
            			$(container+' .Slider-content-scroller').css("left",'-'+width+'px');
            			$(container+' .Slider-content-scroller').prepend('<div class="Slider-content-changeble Slider-content-changeble-vision">'+req.responseJS.output+'</div>');
		            	$(container+' .Slider-content-scroller')
							.animate(
								{
									'left':'+='+width+'px'
								},
								timeout,
								'linear',
								function()
								{
									$(this).children('.Slider-content-changeble').each(function()
									{
										if(!$(this).hasClass('Slider-content-changeble-vision')){$(this).remove();}
									});
									$(container+' .Slider-content-changeble-vision').removeClass('Slider-content-changeble-vision');
									$(container+' .Slider-content-scroller').css("width",width+'px');
									$(container+' .Slider-content-scroller').css("left",'0px');
								}
							);
            		break;
            		case 'next':
            			$(container+' .Slider-content-scroller').width(parseInt(width*2)+'px');
            			$(container+' .Slider-content-scroller').append('<div class="Slider-content-changeble Slider-content-changeble-vision">'+req.responseJS.output+'</div>');
		            	$(container+' .Slider-content-scroller')
							.animate(
								{
									'left':'-='+width+'px'
								},
								timeout,
								'linear',
								function()
								{
									$(this).children('.Slider-content-changeble').each(function()
									{
										if(!$(this).hasClass('Slider-content-changeble-vision')){$(this).remove();}
									});
									$(container+' .Slider-content-changeble-vision').removeClass('Slider-content-changeble-vision');
									$(container+' .Slider-content-scroller').css("width",width+'px');
									$(container+' .Slider-content-scroller').css("left",'0px');
								}
							);
            		break;
            	}
            	if(nav.prev_link == false)
            	{
            		if($(container+" .Slider-prev-active"))
            		{
            			$(container+" .Slider-prev-active").removeClass("Slider-prev-active").addClass("Slider-prev-unactive");
            		}
            	}
            	else if($(container+" .Slider-prev-unactive"))
				{
					$(container+" .Slider-prev-unactive").removeClass("Slider-prev-unactive").addClass("Slider-prev-active");
				}
            	if(nav.next_link == false)
            	{
            		if($(container+" .Slider-next-active"))
            		{
            			$(container+" .Slider-next-active").removeClass("Slider-next-active").addClass("Slider-next-unactive");
            		}
            	}
            	else if($(container+" .Slider-next-unactive"))
				{
					$(container+" .Slider-next-unactive").removeClass("Slider-next-unactive").addClass("Slider-next-active");
				}
            	$(container+" .Slider-navigation-from").val(nav.from);
            }
		}
    }
	var width = $(container+' .Slider-content-scroller').width();
	var height = $(container+' .Slider-content-scroller').height();
    // Prepare request object (automatically choose GET or POST).
    req.open(null, PathToAjaxBackend, true);
	req.send({from:from,module:module,action:action,extra_params:extra_params});
}
function vote(form_element,container_id)
{
	var container = "#"+container_id;
	$(container).prepend('<div class="loader"></div>');
	action = 'vote';
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
			$(".loader").remove();
            //get errors from backend
            if(req.responseText)
            {
                $(container+" .error_text").html(req.responseText);
                $(container+" .error_text").fadeOut(5000);
            }
			//get data from backend		
            if (req.responseJS.error == true)
            {
                $(container+" .error_text").html(req.responseJS.error_text);
                $(container+" .error_text").fadeOut(5000);
           	}
           	else
           	{
           		$(container).fadeOut("slow");
           		$(container).html(req.responseJS.output);
           		$(container).fadeIn("slow");
           		$(container+" .error_text").html(req.responseJS.error_text);
				$(container+" .error_text").fadeOut(5000);
           	}
  		}
	}
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/js/ajax/vote.php', true);
	req.send({form:form_element,action:action});
}
$(document).ready(function(){
	$(".vote_submit_button").live('click',function(){
		form = document.getElementById($(this).parent().parent().attr("id"));
		//alert(form.id)
		vote(form,$("#votes").attr("id"));
	});
	$(".search_type")
		.live('click',function()
			{
				$(this).parent().next("input").attr("value",$(this).attr("id").replace(/search_in_(\w+)/,"$1"));
				$(this).parent().find(".search_type").removeClass("selectedSearchType");
				$(this).addClass("selectedSearchType");
			}
		);
	$(".Slider-prev-active").live('click',function(){
		container_id = $(this).parent().attr("id");
		from = parseInt($("#"+container_id+" .Slider-navigation-from").val());
		switch(container_id)
		{
			case 'poll':
				Slider(parseInt(from-1),'prev',container_id,'normal','poll');
			break;
			case 'consultant':
				Slider(parseInt(from-1),'prev',container_id,'normal','consultant');
			break;
		}
	});
	$(".Slider-next-active").live('click',function(){
		container_id = $(this).parent().attr("id");
		from = parseInt($("#"+container_id+" .Slider-navigation-from").val());
		switch(container_id)
		{
			case 'poll':
				Slider(parseInt(from+1),'next',container_id,'normal','poll');
			break;
			case 'consultant':
				Slider(parseInt(from+1),'next',container_id,'normal','consultant');
			break;
		}
	});
	//$("#rabota_search_select").selectbox();
});
